// 数据库连接池

use anyhow::Result;
use sqlx::{postgres::PgPoolOptions, PgPool};

/// 创建 PostgreSQL 连接池
pub async fn create_pool(database_url: &str, max_connections: u32) -> Result<PgPool> {
    let pool = PgPoolOptions::new()
        .max_connections(max_connections)
        .connect(database_url)
        .await?;
    
    tracing::info!("Database pool created with {} max connections", max_connections);
    Ok(pool)
}

/// 健康检查
pub async fn health_check(pool: &PgPool) -> Result<()> {
    sqlx::query("SELECT 1").execute(pool).await?;
    Ok(())
}
